<?php
/*
   Copyright 2010, Sanket Parab

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
   
   This is a Test User Interface meant for demo purposes.
 */

session_start();
//include and parse config file
require_once 'config.php';
//including library files which containt general purpose functions
$library = array('functions','anchor');
foreach( $library as $lib ) {
	if(file_exists(ROOT .  BRANCH . "library/$lib.php")) {
		require_once(ROOT . BRANCH . "library/$lib.php");
	}
}
// setting includes from application library and classes
if($handle = opendir(ROOT . BRANCH . 'classes')) {
	while(false !== ($file = readdir($handle))) {
		if($file != "." && $file != ".." && $file != '.svn') {
			include_once(ROOT . BRANCH . "classes/$file");
		}
	}
	closedir($handle);
}
//GET Params from the URL currently called
$params = getParams($_SERVER['QUERY_STRING']); //GET params in the query
//check if user is logged in, and do redirection accordingly, if needed
//Access Levels: 0 - No Login only. 1 - Login only; 2: No Website access. 3: All access.
if(!isset($access_level) || $access_level > 3) {
	$access_level = 1;
}
if($access_level == 0) {
	if(isLoggedIn()) {
		$instructor = new Instructor($_SESSION['logged_in']);
		redirect('home.php');
	}
} elseif($access_level == 1) {
	if(!isLoggedIn()) {
		$_SESSION['m'] = '3';
		redirect('index.php');
	} else {
		$instructor = new Instructor($_SESSION['logged_in']);
	}
} elseif($access_level == 2) {
	$_SESSION['m'] = '5';
	redirect('index.php');
} elseif($access_level == 3) {
	if(isLoggedIn()) {
		$instructor = new Instructor($_SESSION['logged_in']);
	}
}
// linking stylesheets and javascript files
$style_sheet = array('default');
if(isset($style)) {
	if(is_array($style)) {
		$style_sheet = array_merge($style_sheet,$style);
	} else {
		array_push($style_sheet,$style);
	}
}
$java_script = array('jquery','default','validate');
if(isset($script)) {
	if(is_array($script)) {
		$java_script = array_merge($java_script,$script);
	} else {
		array_push($java_script,$script);
	}
}
?>